package com.tool.utils;

import java.math.BigInteger;

public class BigIntegerRights {

    /**
     * 计算权限
     * @param rights
     * @return
     */
    public static BigInteger sumRights(String[] rights){
        BigInteger num = new BigInteger("0");
        for(int i=0; i<rights.length; i++){
            num = num.setBit(Integer.parseInt(rights[i]));
        }
        return num;
    }

    /**
     * 检查权限
     * @param sum
     * @param targetRights
     * @return
     */
    public static boolean testRights(BigInteger sum,int targetRights){
        return sum.testBit(targetRights);
    }

    public static void main(String[] args) {
        BigInteger num = new BigInteger("0");
        num = num.setBit(1);
        num = num.setBit(2);

        System.out.println(num);
        System.out.println(num.testBit(1));
        System.out.println(num.testBit(2));
        System.out.println(num.testBit(3));
    }
}
